package com.cn.file;

import java.nio.ByteBuffer;

public class SelectMappedBufferResult {

    /**
     * 数据起始位置（逻辑位移 = 物理位移+起始位移）
     */
    private int startOffset;

    /**
     * 数据块大小
     */
    private int size;

    /**
     * 数据块
     */
    private ByteBuffer byteBuffer;

    private MappFile mappFile;

    public SelectMappedBufferResult(int startOffset, int size, ByteBuffer byteBuffer, MappFile mappFile) {
        this.startOffset = startOffset;
        this.size = size;
        this.byteBuffer = byteBuffer;
        this.mappFile = mappFile;
    }

    public synchronized void release() {
        if (this.mappFile != null) {
            this.mappFile.release();
            this.mappFile = null;
        }
    }

    public int getStartOffset() {
        return startOffset;
    }

    public int getSize() {
        return size;
    }

    public ByteBuffer getByteBuffer() {
        return byteBuffer;
    }

    public MappFile getMappFile() {
        return mappFile;
    }
}
